//
//  UIView+UIViewAdditions.m
//  collection
//
//  Created by 张靖 on 11-10-24.
//  Copyright (c) 2011年 collection. Inc.. All rights reserved.
//

#import "UIView+UIViewAdditions.h"
#import "CBadgeView.h"

#define kUIVIEW_ADDITIONS_BADGEVIEW_TAG 0xa8a86f

@implementation UIView (UIViewAdditions)

- (UIView*) badgeView
{
	return (CBadgeView*) [self viewWithTag:kUIVIEW_ADDITIONS_BADGEVIEW_TAG];
}

- (void) setBadgeValue:(NSString*)badgeStr on:(CGPoint)position
{
	if (badgeStr == nil || [badgeStr length] == 0)
	{
		[[self badgeView] removeFromSuperview];
	}
	else 
	{
		if ([self badgeView] == nil)
		{
			CBadgeView* badgeView = [[CBadgeView alloc] initWithFrame:CGRectNull];
			badgeView.tag = kUIVIEW_ADDITIONS_BADGEVIEW_TAG;
			[self addSubview:badgeView];
			[badgeView release];            
		}
		
		CBadgeView* v = (CBadgeView*)[self badgeView];
		v.badgeValue = badgeStr;
        v.center = position;        
	}
}

@end
